##############################################################  
## MOD Title: Cache Posts System  
## MOD Author: AmigaLink < webmaster@amigalink.de > (Markus Schmidt) http://www.AmigaLink.de  
## MOD Description: File cache for postings to discharge the php interpreter. Cached posts never must be parsed by the bbcode.php thus the performance of the server is improved.  
## MOD Version: 1.0.2  
##  
## Installation Level: Moderate  
## Installation Time: 25 minutes  
## Files To Edit: modcp.php  
##      viewtopic.php  
##      includes/constants.php  
##      includes/functions_post.php  
##      includes/page_tail.php  
##   includes/prune.php  
##      language/lang_english/lang_main.php  
##      templates/subSilver/overall_footer.tpl  
##      templates/subSilver/subSilver.cfg  
##      templates/subSilver/viewtopic_body.tpl  
## Included Files: db_update.php  
##      admin/admin_cache_posts.php  
##      admin/cps-module_configuration.php  
##      admin/cps-module_delete_cache.php  
##      admin/cps-module_delete_unused_files.php  
##      admin/cps-module_resync.php  
##      cache/posts/.htaccess  
##      images/statistik.gif  
##      language/lang_english/lang_admin_cache_posts.php  
##      templates/subSilver/admin/admin_cache_posts.tpl  
##      templates/subSilver/admin/admin_cache_posts_stats.tpl  
##      templates/subSilver/admin/cps_config_body.tpl  
##      templates/subSilver/images/icon_cache_deactivate.gif  
##      templates/subSilver/images/icon_cache_delete.gif  
##   templates/subSilver/images/icon_cache_recycle.gif  
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2  
##############################################################  
## For security purposes, please check: http://www.phpbb.com/mods/  
## for the latest version of this MOD. Although MODs are checked  
## before being allowed in the MODs Database there is no guarantee  
## that there are no security problems within the MOD. No support  
## will be given for MODs not found within the MODs Database which  
## can be found at http://www.phpbb.com/mods/  
##############################################################  
## Author Notes:  
##  
##  At least PHP 4.3.0 are needed!  
##  
##  This hack is released under the GPL License V2.  
##  This hack can be freely used, but not distributed, without permission.  
##  Intellectual Property Rights are retained by the hack author(s)  
##  listed above.  
##  If you change this hack or use some code parts in your work. You MUST give  
##  full information about the original author(s) and website(s) listed above.  
##############################################################  
##  
## MOD History:  
##  
##   2007-02-08 - Version 1.0.2  
##   - fixed a little bug in viewtopic which only arises if "Cache each template" is active  
##   - fixed a bug in modcp which doesn't delete the cache when deleting a topic  
##   - little changes at installation guide  
##   - changes at 'Quiz MOD' addon  
##   - add 'Delete multiple posts' addon in contrib folder  
##   - add 'YOU BBCode' addon in contrib folder  
##  
##   2007-02-06 - Version 1.0.1a  
##   - fixed a little bug in english lang file  
##   (for update replace the language/lang_english/lang_admin_cache_posts.php)  
##  
##   2007-02-03 - Version 1.0.1  
##   - missed statistik.gif added  
##   - fixed little statistik bug (thx to oxpus)  
##   (for update replace the cps-module_resync.php, upload the statistik.gif and run the db_update.php)  
##  
##   2007-02-01 - Version 1.0.0 (First release)  
##   - little style fix  
##  
##   2007-01-28 - Version 0.11.0 rc1  
##   - little style fix (icons)  
##   - little stats speedup  
##   - stats as option  
##   - add topic cache lock  
##  
##   2007-01-20 - Version 0.10.0 beta  
##   - add cache manage functions  
##   - add db_update.php  
##   - stats speedup (thx to oxpus)  
##   - translate to english  
##  
##   2006-12-30 - Version 0.9.0 beta  
##   - rename some variables  
##   - add security check  
##   - add style array for cache indicator  
##   - add ACP tools  
##   - add 'Quiz MOD' add-on in contrib folder  
##   - add 'Ajax' add-on in contrib folder (thx to oxpus)  
##  
##   2006-12-13 - Version 0.1.1 alpha  
##   - Version for alpha testing people (otherwise unreleased)  
##  
##   2006-12-09 - Version 0.1.0  
##   - First Version (unreleased)  
##  
##############################################################  
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD  
##############################################################  
 
#  
#-----[ SQL ]----------------------------------------------------------------  
#  
#  IMPORTANT: If you have changed the table prefix from the default of phpBB2,  
#  please be sure to replace phpBB2 with your prefix BEFORE running this update.  
#  
#  (Alternatively you can run the db_update.php)  
 
ALTER TABLE `phpbb_posts` ADD `parsed` TINYINT( 1 ) DEFAULT '0' NOT NULL ;  
ALTER TABLE `phpbb_posts` ADD `dont_cache` TINYINT( 1 ) DEFAULT '0' NOT NULL ;  
ALTER TABLE `phpbb_posts` ADD `cache_file_md5` VARCHAR( 32 ) DEFAULT NULL ;  
ALTER TABLE `phpbb_topics` ADD `topic_cache_lock` TINYINT( 1 ) DEFAULT '0' NOT NULL ;  
ALTER TABLE `phpbb_topics` ADD INDEX ( `topic_cache_lock` ) ;  
INSERT INTO `phpbb_config` VALUES ('enable_post_cache', '1');  
INSERT INTO `phpbb_config` VALUES ('allow_cache_moderate', '0');  
INSERT INTO `phpbb_config` VALUES ('min_post_cache_size', '100');  
INSERT INTO `phpbb_config` VALUES ('cache_each_template', '0');  
INSERT INTO `phpbb_config` VALUES ('show_cache_stats', '0');  
INSERT INTO `phpbb_config` VALUES ('cache_posts_version', '1.0.2');  
 
#  
#-----[ COPY ]----------------------------------------------------------------  
#  
 
copy root/admin/admin_cache_posts.php to admin/admin_cache_posts.php  
copy root/admin/cps-module_configuration.php to admin/cps-module_configuration.php  
copy root/admin/cps-module_delete_cache.php to admin/cps-module_delete_cache.php  
copy root/admin/cps-module_delete_unused_files.php to admin/cps-module_delete_unused_files.php  
copy root/admin/cps-module_resync.php to admin/cps-module_resync.php  
copy root/cache/posts/.htaccess to cache/posts/.htaccess  
copy root/images/statistik.gif to images/statistik.gif  
copy root/language/lang_english/lang_admin_cache_posts.php to language/lang_english/lang_admin_cache_posts.php  
copy root/templates/subSilver/admin/admin_cache_posts.tpl to templates/subSilver/admin/admin_cache_posts.tpl  
copy root/templates/subSilver/admin/admin_cache_posts_stats.tpl to templates/subSilver/admin/admin_cache_posts_stats.tpl  
copy root/templates/subSilver/admin/cps_config_body.tpl to templates/subSilver/admin/cps_config_body.tpl  
copy root/templates/subSilver/images/icon_cache_deactivate.gif to templates/subSilver/images/icon_cache_deactivate.gif  
copy root/templates/subSilver/images/icon_cache_delete.gif to templates/subSilver/images/icon_cache_delete.gif  
copy root/templates/subSilver/images/icon_cache_recycle.gif to templates/subSilver/images/icon_cache_recycle.gif  
 
#  
#-----[ DIY INSTRUCTIONS ]----------------------------------------------------  
#  
 
Before installation:  
------------------------------------------  
In order to avoid error messages, the data base entrys specified above must be accomplished before the installation.  
 
After installation:  
-------------------  
Set the permissions of the folder cache/posts to CHMOD 777 if you use an UNIX/Linux system.  
Otherwise the MOD could not work.  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
modcp.php  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )  
 
#  
#-----[ BEFORE, ADD ]---------------------------------------------------------  
#  
 
// Cache Posts  
if ( isset($HTTP_POST_VARS[POST_CPS_MANAGE_URL]) || isset($HTTP_GET_VARS[POST_CPS_MANAGE_URL]) )  
{  
   $cps_mode = ( isset($HTTP_POST_VARS[POST_CPS_MANAGE_URL]) ) ? $HTTP_POST_VARS[POST_CPS_MANAGE_URL] : $HTTP_GET_VARS[POST_CPS_MANAGE_URL];  
   $cps_mode = htmlspecialchars($cps_mode);  
}  
else  
{  
   $cps_mode = '';  
}  
// Cache Posts  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
   else  
   {  
      $mode = '';  
   }  
 
#  
#-----[ BEFORE, ADD ]---------------------------------------------------------  
#  
 
// Cache Posts  
   else if ( $cps_mode )  
   {  
      $mode = 'cps_manage';  
   }  
// Cache Posts  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
         if ( $post_id_sql != '' )  
         {  
            $sql = "DELETE  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
            remove_search_post($post_id_sql);  
 
#  
#-----[ AFTER, ADD ]----------------------------------------------------------  
#  
 
            // Cache Posts  
            $cps_delete_array = explode(",", $post_id_sql);  
            foreach ($cps_delete_array as $cps_delete_id)  
            {  
               foreach (glob($phpbb_root_path.'cache/posts/*post_'.intval($cps_delete_id).'.gz') as $cachefile)  
               {  
                  @unlink($cachefile);  
               }  
            }  
            // Cache Posts  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
   default:  
      $page_title = $lang['Mod_CP'];  
 
#  
#-----[ BEFORE, ADD ]---------------------------------------------------------  
#  
 
// Cache Posts  
   case 'cps_manage':  
      $page_title = $lang['Mod_CP'];  
      $redirect_page = ($post_id) ? append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id") : append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id");  
      $template->assign_vars(array(  
         'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')  
      );  
      include($phpbb_root_path . 'includes/page_header.'.$phpEx);  
 
      switch ( $cps_mode )  
      {  
         case 'recycle':  
            $message = $lang['CPS_recycle_message'];  
            foreach (glob($phpbb_root_path.'cache/posts/*post_'.$post_id.'.gz') as $cachefile)  
            {  
               @unlink($cachefile);  
            }  
            $sql = "UPDATE " . POSTS_TABLE . "  
               SET parsed = 0, dont_cache = 0, cache_file_md5 = NULL  
               WHERE post_id = $post_id";  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
            message_die(GENERAL_MESSAGE, $message);  
            break;  
 
         case 'deactivate':  
            $message = $lang['CPS_dont_cache_message'];  
            foreach (glob($phpbb_root_path.'cache/posts/*post_'.$post_id.'.gz') as $cachefile)  
            {  
               @unlink($cachefile);  
            }  
            $sql = "UPDATE " . POSTS_TABLE . "  
               SET parsed = 0, dont_cache = 1, cache_file_md5 = NULL  
               WHERE post_id = $post_id";  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
            message_die(GENERAL_MESSAGE, $message);  
            break;  
 
         case 'delete':  
            $message = $lang['CPS_delete_message'];  
            foreach (glob($phpbb_root_path.'cache/posts/*post_'.$post_id.'.gz') as $cachefile)  
            {  
               @unlink($cachefile);  
            }  
            $sql = "UPDATE " . POSTS_TABLE . "  
               SET parsed = 0, dont_cache = 0, cache_file_md5 = NULL  
               WHERE post_id = $post_id";  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
            message_die(GENERAL_MESSAGE, $message);  
            break;  
 
         case 'recycle_topic':  
            $message = $lang['CPS_recycle_topic_message'];  
            $sql = "SELECT post_id FROM " . POSTS_TABLE . " WHERE topic_id = $topic_id";  
            if ( !($result = $db->sql_query($sql)) )  
            {  
               message_die(GENERAL_ERROR, 'Could not get topic posts information', '', __LINE__, __FILE__, $sql);  
            }  
            while ( $row = $db->sql_fetchrow($result) )  
            {  
               foreach (glob($phpbb_root_path.'cache/posts/*post_'.intval($row['post_id']).'.gz') as $cachefile)  
               {  
                  @unlink($cachefile);  
               }  
            }  
            $db->sql_freeresult($result);  
 
            $sql = "UPDATE " . TOPICS_TABLE . "  
               SET topic_cache_lock = 0  
               WHERE topic_id = $topic_id  
               AND topic_cache_lock = 1";  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
            $sql = "UPDATE " . POSTS_TABLE . "  
               SET parsed = 0, dont_cache = 0, cache_file_md5 = NULL  
               WHERE topic_id = $topic_id";  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
            message_die(GENERAL_MESSAGE, $message);  
            break;  
 
         case 'deactivate_topic':  
            $message = $lang['CPS_dont_cache_topic_message'];  
            $sql = "SELECT post_id FROM " . POSTS_TABLE . " WHERE topic_id = $topic_id";  
            if ( !($result = $db->sql_query($sql)) )  
            {  
               message_die(GENERAL_ERROR, 'Could not get topic posts information', '', __LINE__, __FILE__, $sql);  
            }  
            while ( $row = $db->sql_fetchrow($result) )  
            {  
               foreach (glob($phpbb_root_path.'cache/posts/*post_'.intval($row['post_id']).'.gz') as $cachefile)  
               {  
                  @unlink($cachefile);  
               }  
            }  
            $db->sql_freeresult($result);  
 
            $sql = "UPDATE " . TOPICS_TABLE . "  
               SET topic_cache_lock = 1  
               WHERE topic_id = $topic_id";  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
            $sql = "UPDATE " . POSTS_TABLE . "  
               SET parsed = 0, dont_cache = 1, cache_file_md5 = NULL  
               WHERE topic_id = $topic_id";  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
            message_die(GENERAL_MESSAGE, $message);  
            break;  
 
         case 'delete_topic':  
            $message = $lang['CPS_delete_topic_message'];  
            $sql = "SELECT post_id FROM " . POSTS_TABLE . " WHERE topic_id = $topic_id";  
            if ( !($result = $db->sql_query($sql)) )  
            {  
               message_die(GENERAL_ERROR, 'Could not get topic posts information', '', __LINE__, __FILE__, $sql);  
            }  
            while ( $row = $db->sql_fetchrow($result) )  
            {  
               foreach (glob($phpbb_root_path.'cache/posts/*post_'.intval($row['post_id']).'.gz') as $cachefile)  
               {  
                  @unlink($cachefile);  
               }  
            }  
            $db->sql_freeresult($result);  
 
            $sql = "UPDATE " . POSTS_TABLE . "  
               SET parsed = 0, dont_cache = 0, cache_file_md5 = NULL  
               WHERE topic_id = $topic_id";  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
            message_die(GENERAL_MESSAGE, $message);  
            break;  
 
         default:  
            message_die(GENERAL_MESSAGE, 'CPS: Manage mode failed');  
            break;  
      }  
      break;  
// Cache Posts  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
viewtopic.php  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
//  
// Start initial var setup  
 
#  
#-----[ BEFORE, ADD ]---------------------------------------------------------  
#  
 
// Cache Posts  
// Here you can change the style of the CPS indicators  
$CPS_Indicator = array(  
   'cached' => '<span style="color: limegreen"><b>&bull;</b></span>',  
   'not_cached' => '<span style="color: green"><b>&bull;</b></span>',  
   'error' => '<span style="color: red"><b>&bull;</b></span>',  
   'dont_cache' => '<span style="color: yellow"><b>&bull;</b></span>',  
   'off_but_cached' => '<span style="color: orange"><b>&bull;</b></span>',  
   'off' => '<span style="color: black"><b>&bull;</b></span>');  
// Cache Posts  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
# Note this line maybe much longer  
 
$sql = "SELECT t.topic_id, t.topic_title, t.topic_status,  
 
#  
#-----[ IN-LINE FIND ]--------------------------------------------------------  
#  
 
t.topic_last_post_id  
 
#  
#-----[ IN-LINE AFTER, ADD ]--------------------------------------------------  
#  
 
, t.topic_cache_lock  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
//  
// Send vars to template  
 
#  
#-----[ BEFORE, ADD ]---------------------------------------------------------  
#  
 
// Cache Posts  
if ($board_config['enable_post_cache'])  
{  
   $cps_topic_img = '<a href="modcp.'.$phpEx.'?'.POST_CPS_MANAGE_URL.'=recycle_topic&amp;'.POST_TOPIC_URL.'='.$topic_id.'&amp;sid='.$userdata['session_id'].'"><img src="'.$images['icon_cache_recycle_topic'].'" alt="'.$lang['CPS_recycle_topic'].'" title="'.$lang['CPS_recycle_topic'].'" border="0" /></a>&nbsp;';  
   $cps_topic_img .= ( !$forum_topic_data['topic_cache_lock'] ) ? '<a href="modcp.'.$phpEx.'?'.POST_CPS_MANAGE_URL.'=deactivate_topic&amp;'.POST_TOPIC_URL.'='.$topic_id.'&amp;sid='.$userdata['session_id'].'"><img src="'.$images['icon_cache_deactivate_topic'].'" alt="'.$lang['CPS_dont_cache_topic'].'" title="'.$lang['CPS_dont_cache_topic'].'" border="0" /></a>&nbsp;' : '';  
}  
else  
{  
   $cps_topic_img = ($userdata['user_level'] == ADMIN) ? '<a href="modcp.'.$phpEx.'?'.POST_CPS_MANAGE_URL.'=delete_topic&amp;'.POST_TOPIC_URL.'='.$topic_id.'&amp;sid='.$userdata['session_id'].'"><img src="'.$images['icon_cache_delete_topic'].'" alt="'.$lang['CPS_delete_topic'].'" title="'.$lang['CPS_delete_topic'].'" border="0" /></a>&nbsp;' : '';  
}  
// Cache Posts  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
   'S_TOPIC_ADMIN' => $topic_mod,  
 
#  
#-----[ AFTER, ADD ]----------------------------------------------------------  
#  
 
// Cache Posts  
   'S_CPS_IMG_TOPIC' => ( $is_auth['auth_mod'] && $board_config['allow_cache_moderate'] || $userdata['user_level'] == ADMIN ) ? $cps_topic_img : '',  
// Cache Posts  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
   $message = $postrow[$i]['post_text'];  
 
#  
#-----[ REPLACE WITH ]--------------------------------------------------------  
#  
 
// Cache Posts  
   $parsed = ($board_config['enable_post_cache']) ? $postrow[$i]['parsed'] : 0;  
   if (!$parsed || !$board_config['enable_post_cache'])  
   {  
      $message = $postrow[$i]['post_text'];  
   } else {  
      $cstyle = ($userdata['session_logged_in'] && $userdata['user_style'] != $board_config['default_style'] && $board_config['cache_each_template']) ? $userdata['user_style'].'_' : '';  
      $cachefile = 'cache/posts/'.$cstyle.'post_'.$postrow[$i]['post_id'].'.gz';  
      if (file_exists($cachefile) && filemtime($cachefile) >= $postrow[$i]['post_edit_time'] && $postrow[$i]['cache_file_md5'] == md5_file($cachefile))  
      {  
         $handle = @fopen($phpbb_root_path.$cachefile, 'r');  
         $message = gzinflate(@fread($handle, @filesize($cachefile)+1));  
         @fclose($handle);  
      } else {  
         @unlink($cachefile);  
         $message = $postrow[$i]['post_text'];  
         $parsed = 0;  
      }  
   }  
// Cache Posts  
//   $message = $postrow[$i]['post_text'];  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
      if ( $postrow[$i]['enable_html'] )  
      {  
         $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);  
      }  
 
#  
#-----[ REPLACE WITH ]--------------------------------------------------------  
#  
 
      // Cache Posts  
      if (!$parsed || !$board_config['enable_post_cache'])  
      {  
         if ( $postrow[$i]['enable_html'] )  
         {  
            $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);  
         }  
      }  
      // Cache Posts  
/*      if ( $postrow[$i]['enable_html'] )  
      {  
         $message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);  
      }*/  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
      if ($bbcode_uid != '')   
      {   
         $message = ($board_config['allow_bbcode']) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace("/\:$bbcode_uid/si", '', $message);   
      }  
 
#  
#-----[ REPLACE WITH ]--------------------------------------------------------  
#  
 
      // Cache Posts  
      if (!$parsed || !$board_config['enable_post_cache'])  
      {  
         if ( $bbcode_uid != '' )  
         {  
            $message = ($board_config['allow_bbcode']) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace("/\:$bbcode_uid/si", '', $message);   
         }  
      }  
      // Cache Posts  
/*      if ( $bbcode_uid != '' )  
      {  
         $message = ($board_config['allow_bbcode']) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace("/\:$bbcode_uid/si", '', $message);   
      }*/  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
   $message = make_clickable($message);  
 
#  
#-----[ REPLACE WITH ]--------------------------------------------------------  
#  
 
   (!$parsed || !$board_config['enable_post_cache']) ? $message = make_clickable($message) : ''; // Cache Posts  
//   $message = make_clickable($message);  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
      if ( $postrow[$i]['enable_smilies'] )  
      {  
         $message = smilies_pass($message);  
      }  
 
#  
#-----[ REPLACE WITH ]--------------------------------------------------------  
#  
 
      (!$parsed || !$board_config['enable_post_cache']) ? (($postrow[$i]['enable_smilies']) ? $message = smilies_pass($message) : '') : ''; // Cache Posts  
/*      if ( $postrow[$i]['enable_smilies'] )  
      {  
         $message = smilies_pass($message);  
      }*/  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
   //  
   // Highlight active words (primarily for search)  
   //  
 
#  
#-----[ BEFORE, ADD ]---------------------------------------------------------  
#  
 
// Cache Posts  
   if (!$parsed && $board_config['enable_post_cache'] && ($postrow[$i]['enable_bbcode'] || $postrow[$i]['enable_html']) && !$postrow[$i]['dont_cache'] && !$forum_topic_data['topic_cache_lock'])  
   {  
      $cstyle = ($userdata['session_logged_in'] && $userdata['user_style'] != $board_config['default_style'] && $board_config['cache_each_template']) ? $userdata['user_style'].'_' : '';  
      $cachefile = 'cache/posts/'.$cstyle.'post_'.$postrow[$i]['post_id'].'.gz';  
      $handle = @fopen($phpbb_root_path.$cachefile, 'w');  
      @flock($handle, LOCK_EX);  
      $packed = gzdeflate($message, 9);  
      $cf_size = @fwrite($handle, $packed);  
      @flock($handle, LOCK_UN);  
      @fclose($handle);  
      @chmod($phpbb_root_path.$cachefile, 0666);  
 
      if ($cf_size)  
      {  
         if ($cf_size > $board_config['min_post_cache_size'])  
         {  
            $parsed = 1;  
            $sql = "UPDATE " . POSTS_TABLE . "  
               SET parsed = 1, cache_file_md5 = '".md5_file($cachefile)."'  
               WHERE post_id = ".$postrow[$i]['post_id'];  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
         }  
         else  
         {  
            $parsed = 0;  
            $postrow[$i]['dont_cache'] = 1;  
            foreach (glob($phpbb_root_path.'cache/posts/*post_'.$postrow[$i]['post_id'].'.gz') as $cachefile)  
            {  
               @unlink($cachefile);  
            }  
            $sql = "UPDATE " . POSTS_TABLE . "  
               SET parsed = 0, dont_cache = 1, cache_file_md5 = NULL  
               WHERE post_id = ".$postrow[$i]['post_id'];  
            if(!$result = $db->sql_query($sql))  
            {  
               message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
            }  
         }  
      }  
      else if ($postrow[$i]['parsed'])  
      {  
         $parsed = 0;  
         $sql = "UPDATE " . POSTS_TABLE . "  
            SET parsed = 0, cache_file_md5 = NULL  
            WHERE post_id = ".$postrow[$i]['post_id'];  
         if(!$result = $db->sql_query($sql))  
         {  
            message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
         }  
      }  
      $postrow[$i]['parsed'] = $parsed;  
   }  
   else if ( $forum_topic_data['topic_cache_lock'] )  
   {  
      $parsed = 0;  
      $postrow[$i]['dont_cache'] = 1;  
      $sql = "UPDATE " . POSTS_TABLE . "  
         SET parsed = 0, dont_cache = 1, cache_file_md5 = NULL  
         WHERE post_id = ".$postrow[$i]['post_id'];  
      if(!$result = $db->sql_query($sql))  
      {  
         message_die(GENERAL_ERROR, 'Could not update parse info', '', __LINE__, __FILE__, $sql);  
      }  
      $postrow[$i]['parsed'] = $parsed;  
   }  
   if ($board_config['enable_post_cache'])  
   {  
      $parse_status = ($parsed) ? $CPS_Indicator['cached'] : (($postrow[$i]['dont_cache']) ? $CPS_Indicator['dont_cache'] : ((!$postrow[$i]['enable_bbcode'] && !$postrow[$i]['enable_html']) ? $CPS_Indicator['not_cached'] : $CPS_Indicator['error']));  
      $cps_img = (!$forum_topic_data['topic_cache_lock']) ? '<a href="modcp.'.$phpEx.'?'.POST_CPS_MANAGE_URL.'=recycle&amp;'.POST_POST_URL.'='.$postrow[$i]['post_id'].'&amp;'.POST_TOPIC_URL.'='.$postrow[$i]['topic_id'].'&amp;sid='.$userdata['session_id'].'"><img src="'.$images['icon_cache_recycle'].'" alt="'.$lang['CPS_recycle'].'" title="'.$lang['CPS_recycle'].'" border="0" /></a>' : '';  
      $cps_img .= ($parsed) ? ' <a href="modcp.'.$phpEx.'?'.POST_CPS_MANAGE_URL.'=deactivate&amp;'.POST_POST_URL.'='.$postrow[$i]['post_id'].'&amp;'.POST_TOPIC_URL.'='.$postrow[$i]['topic_id'].'&amp;sid='.$userdata['session_id'].'"><img src="'.$images['icon_cache_deactivate'].'" alt="'.$lang['CPS_dont_cache'].'" title="'.$lang['CPS_dont_cache'].'" border="0" /></a>' : '';  
   } else {  
      $parse_status = ($postrow[$i]['parsed']) ? $CPS_Indicator['off_but_cached'] : $CPS_Indicator['off'] ;  
      $cps_img = ($postrow[$i]['parsed'] && $userdata['user_level'] == ADMIN) ? '<a href="modcp.'.$phpEx.'?'.POST_CPS_MANAGE_URL.'=delete&amp;'.POST_POST_URL.'='.$postrow[$i]['post_id'].'&amp;'.POST_TOPIC_URL.'='.$postrow[$i]['topic_id'].'&amp;sid='.$userdata['session_id'].'"><img src="'.$images['icon_cache_delete'].'" alt="'.$lang['CPS_delete'].'" title="'.$lang['CPS_delete'].'" border="0" /></a>' : '';  
   }  
// Cache Posts  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
      'DELETE' => $delpost,  
 
#  
#-----[ AFTER, ADD ]----------------------------------------------------------  
#  
 
      // Cache Posts  
      'CPS_STATUS' => $parse_status,  
      'CPS_IMG' => ($is_auth['auth_mod'] && $board_config['allow_cache_moderate'] || $userdata['user_level'] == ADMIN) ? $cps_img : '',  
      // Cache Posts  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
includes/constants.php  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
define('POST_GROUPS_URL', 'g');  
 
#  
#-----[ AFTER, ADD ]----------------------------------------------------------  
#  
 
define('POST_CPS_MANAGE_URL', 'cpsm');  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
includes/functions_post.php  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
   if ($mode == 'editpost')  
   {  
      remove_search_post($post_id);  
 
#  
#-----[ AFTER, ADD ]----------------------------------------------------------  
#  
 
      // Cache Posts  
      foreach (glob($phpbb_root_path.'cache/posts/*post_'.$post_id.'.gz') as $cachefile)  
      {  
         @unlink($cachefile);  
      }  
      // Cache Posts  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
# Note the line is much longer!!!  
 
   $sql = ($mode != "editpost") ? "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip,  
 
#  
#-----[ IN-LINE FIND ]--------------------------------------------------------  
#  
 
"UPDATE " . POSTS_TABLE . " SET post_username = '$post_username', enable_bbcode = $bbcode_on, enable_html = $html_on, enable_smilies = $smilies_on, enable_sig = $attach_sig  
 
#  
#-----[ IN-LINE AFTER, ADD ]--------------------------------------------------  
#  
 
, parsed = 0, dont_cache = 0, cache_file_md5 = NULL  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id)  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
      $sql = "DELETE FROM " . POSTS_TABLE . "  
         WHERE post_id = $post_id";  
      if (!$db->sql_query($sql))  
      {  
         message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);  
      }  
 
#  
#-----[ AFTER, ADD ]----------------------------------------------------------  
#  
 
      // Cache Posts  
      foreach (glob($phpbb_root_path.'cache/posts/*post_'.$post_id.'.gz') as $cachefile)  
      {  
         @unlink($cachefile);  
      }  
      // Cache Posts  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
includes/page_tail.php  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
//  
// Show the overall footer.  
//  
 
#  
#-----[ AFTER, ADD ]----------------------------------------------------------  
#  
# Do not change this copyright info!  
 
// We request you retain the full copyright notice below including the link to   www.amigalink.de.  
// This not only gives respect to the large amount of time given freely by the developers  
// but also helps build interest, traffic and use the works done by AmigaLink.  
// If you refuse to include even this then support on our forums may be affected!  
 
$cps_status = ($board_config['enable_post_cache']) ? 'Cache Posts System &copy; 2006 <a href="http://www.amigalink.de/" target="_AmigaLink" class="copyright">AmigaLink</a><br />' : ''; // Cache Posts  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
   'TRANSLATION_INFO' => (isset($lang['TRANSLATION_INFO'])) ? $lang['TRANSLATION_INFO'] : ((isset($lang['TRANSLATION'])) ? $lang['TRANSLATION'] : ''),  
 
#  
#-----[ BEFORE, ADD ]---------------------------------------------------------  
#  
 
   'CPS_STATUS' => $cps_status,  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
includes/prune.php  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
      $sql_post = '';  
      while ( $row = $db->sql_fetchrow($result) )  
      {  
         $sql_post .= ( ( $sql_post != '' ) ? ', ' : '' ) . $row['post_id'];  
 
#  
#-----[ AFTER, ADD ]----------------------------------------------------------  
#  
 
         // Cache Posts  
         foreach (glob($phpbb_root_path.'cache/posts/*post_'.$row['post_id'].'.gz') as $cachefile)  
         {  
            @unlink($cachefile);  
         }  
         // Cache Posts  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
language/lang_english/lang_main.php  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
?>  
 
#  
#-----[ BEFORE, ADD ]---------------------------------------------------------  
#  
 
// Cache Posts  
$lang['Cache_Posts_System'] = 'Cache Posts System';  
$lang['CPS_recycle'] = 'Cache renew';  
$lang['CPS_recycle_message'] = 'The Cache of this post is now deleted and with the next call is renewed';  
$lang['CPS_dont_cache'] = 'Do not cache';  
$lang['CPS_dont_cache_message'] = 'For this post the Cache is deleted and deactivated';  
$lang['CPS_delete'] = 'Delete cache';  
$lang['CPS_delete_message'] = 'The Cache of this post was deleted';  
$lang['CPS_recycle_topic'] = 'Topic cache renew';  
$lang['CPS_recycle_topic_message'] = 'The Cache of this topic is now deleted and with the next call is renewed';  
$lang['CPS_dont_cache_topic'] = 'Dont cache this topic';  
$lang['CPS_dont_cache_topic_message'] = 'For this topic the Cache is deleted and deactivated';  
$lang['CPS_delete_topic'] = 'Topic cache delete';  
$lang['CPS_delete_topic_message'] = 'The Cache of this topic was deleted';  
// Cache Posts  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
templates/subSilver/overall_footer.tpl  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
Powered by <a href="http://www.phpbb.com/" target="_phpbb" class="copyright">phpBB</a> &copy; 2001, 2005 phpBB Group<br />{TRANSLATION_INFO}</span></div>  
 
#  
#-----[ IN-LINE FIND ]---------------------------------------------------------  
#  
 
phpBB Group<br />  
 
#  
#-----[ IN-LINE AFTER, ADD ]---------------------------------------------------  
#  
#   We request you retain the full copyright notice below including the link to   www.amigalink.de.  
#   This not only gives respect to the large amount of time given freely by the developers  
#   but also helps build interest, traffic and use the works done by AmigaLink.  
#   If you refuse to include even this then support on our forums may be affected!  
 
{CPS_STATUS}  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
templates/subSilver/subSilver.cfg  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
?>  
 
#  
#-----[ BEFORE, ADD ]---------------------------------------------------------  
#  
 
// Cache Posts  
$images['icon_cache_recycle'] = "$current_template_images/icon_cache_recycle.gif";  
$images['icon_cache_deactivate'] = "$current_template_images/icon_cache_deactivate.gif";  
$images['icon_cache_delete'] = "$current_template_images/icon_cache_delete.gif";  
$images['icon_cache_recycle_topic'] = "$current_template_images/topic_cache_recycle.gif";  
$images['icon_cache_deactivate_topic'] = "$current_template_images/topic_cache_deactivate.gif";  
$images['icon_cache_delete_topic'] = "$current_template_images/topic_cache_delete.gif";  
// Cache Posts  
 
#  
#-----[ OPEN ]----------------------------------------------------------------  
#  
 
templates/subSilver/viewtopic_body.tpl  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
            <td width="100%"><a href="{postrow.U_MINI_POST}"><img src="{postrow.MINI_POST_IMG}" width="12" height="9" alt="{postrow.L_MINI_POST_ALT}" title="{postrow.L_MINI_POST_ALT}" border="0" /></a><span class="postdetails">{L_POSTED}: {postrow.POST_DATE}<span class="gen">&nbsp;</span>&nbsp; &nbsp;{L_POST_SUBJECT}: {postrow.POST_SUBJECT}</span></td>  
 
#  
#-----[ IN-LINE FIND ]--------------------------------------------------------  
#  
 
{L_POSTED}: {postrow.POST_DATE}<span class="gen">&nbsp;</span>  
 
#  
#-----[ IN-LINE AFTER, ADD ]--------------------------------------------------  
#  
 
{postrow.CPS_STATUS}  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
            <td valign="top" nowrap="nowrap">{postrow.QUOTE_IMG} {postrow.EDIT_IMG} {postrow.DELETE_IMG} {postrow.IP_IMG}</td>  
 
 
#  
#-----[ IN-LINE FIND ]--------------------------------------------------------  
#  
 
{postrow.EDIT_IMG}  
 
#  
#-----[ IN-LINE AFTER, ADD ]--------------------------------------------------  
#  
 
 {postrow.CPS_IMG}  
 
#  
#-----[ FIND ]----------------------------------------------------------------  
#  
 
     {S_TOPIC_ADMIN}</td>  
 
#  
#-----[ IN-LINE FIND ]--------------------------------------------------------  
#  
 
{S_TOPIC_ADMIN}  
 
#  
#-----[ IN-LINE AFTER, ADD ]--------------------------------------------------  
#  
 
{S_CPS_IMG_TOPIC}  
 
#  
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------------  
#  
# EoM 
